<template>
    <div class="view">
        <div class="logo-view">
            <img :src="logo" alt="">
        </div>
        <div class="form-view">
            <Form ref="formInline" :model="data.data" :rules="ruleInline">
                <FormItem prop="phone">
                    <Input type="text" v-model="data.data.phone" placeholder="请输入您需要登录的用户名" :maxlength='11'>
                        <Icon type="ios-person-outline" slot="prepend"></Icon>
                    </Input>
                </FormItem>
                <FormItem prop="password">
                    <Input type="password" v-model="data.data.password" placeholder="请输入密码">
                        <Icon type="ios-locked-outline" slot="prepend"></Icon>
                    </Input>
                </FormItem>
                <FormItem>
                    <Button type="primary" style="width: 100%;" :loading="data.isLoading" @click="handleSubmit('formInline')">登录</Button>
                </FormItem>
            </Form>
        </div>
    </div>
</template>

<script>
var phoneReg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/; 
import $ from 'jquery'
    export default {
        props: ['data'],
        data() {
            return {
                logo: '',
                ruleInline: {
                    phone: [
                        { required: true, message: '请输入账号', trigger: 'blur' },
                        { pattern: phoneReg, message: '请正确输入手机号', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '请正确输入密码', trigger: 'blur' },
                        { type: 'string', min: 6, message: '密码最少6位', trigger: 'blur' }
                    ]
                }
            }
        },
        mounted() {
            let user = $('.ivu-input-group-prepend');
            for(let i = 0; i < user.length; i++) {
                user[i].style.background = 'rgba(255,255,255,0.1)';
                user[i].style.color = '#ffffff';
                user[i].style.fontSize = "18px";
            }
            let input = $('.ivu-input');
            for(let i = 0; i < input.length; i++) {
                input[i].style.color = 'rgba(255, 255, 255, 0.6)'
            }
        },
        methods: {
            handleSubmit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.$emit('on-submit', this.data);
                    } else {
                        this.$Message.error('账号密码错误!');
                    }
                })
            }
        }
    }
</script>

<style scoped lang="less">
.view {
    width: 5.2rem;
    height: 4.1rem;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 .12rem 0 rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    .logo-view {
        width: 100%;
        height: .5rem;
        text-align: center;
        margin-top: .5rem;
        margin-bottom: .4rem;
        img {
            width: 1.4rem;
            height: .5rem;
        }
    }
    .form-view {
        width: 4rem;
        margin: 0 auto;
    }
}
</style>